package LeetCode;

import Constructs.ListNode;
import Constructs.TreeNode;

import java.util.ArrayList;
import java.util.List;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/5/30.
//
//https://leetcode.cn/problems/binary-tree-inorder-traversal/description/
public class 二叉树的中序遍历 {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(1,null,new TreeNode(2,new TreeNode(3,null,null),null));
        System.out.println(inorderTraversal(root));
    }
    public static List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        if(root == null)return list;
        traverse(root,list);
        return list;
    }

    private static void traverse(TreeNode point, List<Integer> list) {
        if(point.left != null){
            traverse(point.left,list);
        }
        list.add(point.val);
        if(point.right != null){
            traverse(point.right,list);
        }
    }
}
